<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子20-JS进阶（二）</title>
    </head>
    <body class="cols">
        <pre>
            <code>
                    // 例子20

                    //有输入但是没有返回值
                    function setBackgroundColor(el, color) {
                        el.style.backgroundColor = color;
                    }

                    // 多处使用
                    var el1 = document.querySelector('.rectangle');
                    var el2 = document.querySelector('.circle');
                    setBackgroundColor(el1, 'red');
                    setBackgroundColor(el2, 'red');
            </code>
        </pre>
        <pre>
            <code>
                    //有输入有返回值
                    function setBackgroundColor(el, color) {
                        el.style.backgroundColor = color;
                            return color; // 有返回值
                    }

                    // 多处使用
                    var el1 = document.querySelector('.rectangle');
                    var el2 = document.querySelector('.circle');
                    var el1_color = setBackgroundColor(el1, 'red');
                    var el2_color = setBackgroundColor(el2, el1_color);
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/20.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>